<template>
    <div class="editName">
      <van-field v-model="userName" clearable placeholder="请填写用户名" />
      <div style="padding: 0 15px">
        <van-button type="info" block :disabled="isDisabled" class="submit" @click="submit"
          >提交</van-button
        >
      </div>
  </div>
</template>
<script>
import { updateUserName } from '../service/service.js'
export default {
  name: 'EditName',
  data () {
    return {
      userName: '',
      isDisabled: false
    }
  },
  created () {
    this.userName = this.$route.query.userName
  },
  watch: {
    value2 (newVal, oldVal) {
      if (newVal !== '') {
        this.isDisabled = false
      } else {
        this.isDisabled = true
      }
    }
  },
  methods: {
    submit () {
      updateUserName({ userName: this.userName })
        .then((res) => {
          const data = res.data
          if (data.ret !== 0) {
            this.$toast(data.msg)
            return false
          }
          this.$toast(data.msg)
          this.$router.back()
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="less" scoped>
.editName{
  padding-top: 10px;
}
.submit {
  margin-top: 80px;
  border-radius: 5px;
}
</style>
